package nl.infodation.emr.pricingservice.entity;

import java.io.Serializable;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

@Entity
@Table(name = "user")
public class User implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@Column(name = "user_name", nullable = false)
	private String username;

	@Column(name = "password")
	private String password;

	@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
	@JoinTable(name = "user_see", joinColumns = { @JoinColumn(name = "username", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "country_id", nullable = false, updatable = false) })
	private List<SystemValue> countries;

	@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.MERGE)
	@LazyCollection(LazyCollectionOption.EXTRA)
	@JoinColumn(name = "role_id")
	private Role role;

	@Column(name = "first_name")
	private String firstName;

	@Column(name = "last_name")
	private String lastName;

	@Column(name = "is_super_admin", columnDefinition = "bit", nullable = false)
	private boolean superAdmin;

	@Column(name = "is_normal_admin", columnDefinition = "bit", nullable = false)
	private boolean normalAdmin;

	@Column(name = "is_active", columnDefinition = "bit")
	private boolean isActive;

	public String getUsername() {
		return username;
	}

	public void setUsername(String userName) {
		this.username = userName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public List<SystemValue> getCountries() {
		return countries;
	}

	public void setCountries(List<SystemValue> countries) {
		this.countries = countries;
	}

	public Role getRole() {
		return role;
	}

	public void setRole(Role role) {
		this.role = role;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public boolean isSuperAdmin() {
		return superAdmin;
	}

	public void setSuperAdmin(boolean superAdmin) {
		this.superAdmin = superAdmin;
	}

	public boolean isNormalAdmin() {
		return normalAdmin;
	}

	public void setNormalAdmin(boolean normalAdmin) {
		this.normalAdmin = normalAdmin;
	}

	public boolean isActive() {
		return isActive;
	}

	public void setActive(boolean isActive) {
		this.isActive = isActive;
	}

	public User cloneWithoutKey() {
		User u = new User();
		u.setUsername(this.getUsername());
		u.setPassword(this.getPassword());
		u.setRole(this.getRole());
		u.setFirstName(this.getFirstName());
		u.setLastName(this.getLastName());
		u.setActive(this.isActive());
		return u;
	}

}
